<template>
  <div class="app-container">
    <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-="82px">
       <el-form-item label="任务名称" prop="id">
           <el-select v-model="queryParams.task_his_id" clearable  placeholder="请选任务名称">
             <el-option
                 v-for="item in taskhisList"
                 :key="item.id"
                 :label="item.task_name"
                 :value="item.id"
             ></el-option>
           </el-select>
       </el-form-item>
      <el-form-item label="池子编号" prop="pond_name" width="140">
          <el-select v-model="queryParams.pond_name" placeholder="选池子编号">
            <el-option
                v-for="item in pool_nums"
                :key="item.key"
                :label="item.pond_name"
                :value="item.pond_num"
            ></el-option>
          </el-select>
      </el-form-item>
      <el-form-item label="采集时间">
        <el-date-picker
            v-model="queryParams.create_times"
            style="width: 215px" value-format="yyyy-MM-dd" format="yyyy-MM-dd"
            type="daterange"
            range-separator="-"
            start-placeholder="开始日期"
            end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['nssc:aerationresult:xjcjremove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['nssc:aerationresult:export']"
        >导出</el-button>
      </el-col>
  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
<!--  数据列表区域-->
    <el-table v-loading="loading" :data="cjfxjgList" @selection-change="handleSelectionChange" :cell-style="{borderColor:'rgb(1 5 43)'}" :header-cell-style="{borderColor: 'rgb(1 5 43)'}" >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="池子编号" align="center" prop="pond_num" />
      <el-table-column label="标签号" align="center" prop="point" />
      <el-table-column label="分析内容" align="center" prop="fxlr"/>
      <el-table-column label="阀门状态" align="center" prop="fmzt" />
      <el-table-column label="标尺读值" align="center" prop="ruler_value">
        <template slot-scope="scope">
          <span v-if=" typeof scope.row.ruler_value=='undefined' || scope.row.ruler_value==null || scope.row.ruler_value==''">-------</span>
          <span v-else >{{scope.row.ruler_value}}</span>
        </template>
      </el-table-column>
      <el-table-column label="告警状态" align="center" prop="state">
        <template slot-scope="scope">
          <el-tag style="color: #C03639" v-if="scope.row.state==1">告警</el-tag>
          <el-tag v-else >正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="采集时间" align="center" prop="creater_time">
        <template slot-scope="scope">
          <span>{{parseTime(scope.row.creater_time) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              v-if="scope.row.video_path!=null && scope.row.video_path!=''"
              @click="handleViewVD1(scope.row)"
              v-hasPermi="['nssc:aerationresult:video']"
          >结果视频</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['nssc:aerationresult:xjcjremove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<!--列表分页区域-->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);"
    />
    <!-- 视频回放对话框-->
    <el-dialog :title="title" :visible.sync="open" width="900px">
      <videoPlayer class="vjs-custom-skin videoPlayer" ref="videoplayer" :playsinline="true" width="750px" height="250px"
                   :options="playerOptions" customEventName="changed">
      </videoPlayer>
      <div slot="footer" class="dialog-footer">
        <el-button @click="open = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {cjfxjgReport, xjcjsjDelete} from "@/api/nssc/patroltask/patroltask";
import "@/assets/styles/robt-bg.css";
import {getResultVideo, listAerationPort1} from "@/api/nssc/aerationresult/aerationresult";
import {videoPlayer} from "vue-video-player";
import 'video.js/dist/video-js.css';
export default {
  components: {
    videoPlayer,
  },
  data() {
    return {
      //遮罩层
      loading: true,
      //选中数组
      ids: [],
      //非单个禁用
      single: true,
      pond_name:"",
      //非多个禁用
      multiple: true,
      //显示搜索条件
      showSearch: true,
      //总条数
      total: 0,
      cjfxjgList:[],
      taskhisList:[],
      //弹出层标题
      title: "",
      //是否显示弹出层
      open: false,
      //查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        task_his_id: "",
        create_times: [],
      }, pool_nums:[
        {pond_num:1,pond_name:'R滤格'},{pond_num:2,pond_name:'S滤格'},{pond_num:3,pond_name:'T滤格'},{pond_num:4,pond_name:'U滤格'},
        {pond_num:5,pond_name:'V滤格'},{pond_num:6,pond_name:'W滤格'},{pond_num:7,pond_name:'X滤格'},{pond_num:8,pond_name:'Y滤格'}
      ],
      playerOptions: {
        width: "750px",
        height: "250px",
        language: "zh-CN",
        playbackRates: [0.7, 1.0, 1.5, 2.0],// 播放速度  美团附近药店买点药涂抹下
        muted: false,// 默认情况下将会消除任何音频
        autoplay: false,// 如果true,浏览器准备好时开始回放。
        controls: true, //不显示暂停、声音、进度条组件
        loop: false, // 视频一结束就重新开始。
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        sources: [
          {
            type: "video/mp4",
            src: "", // url地址
          },
        ],
        controlBar: {
          timeDivider: false, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: true, // 是否显示剩余时间功能
          fullscreenToggle: true, // 是否显示全屏按钮
        }
      }
    };
  },
  created() {
    this.getList();
    this.gettaskhisList();
  },
  methods: {
    getSelectdata(row) {
      this.queryParams.pond_num = row.pond_num;
      this.getList();
    },
    handleViewVD1(row) {
      let mediaUrl = row.video_path;
      this.getMedia1(mediaUrl);
    },
    getMedia1(mediaUrl) {
      getResultVideo(mediaUrl).then(response => {
        if(typeof response.data !="undefined"){
          let videopath = response.data.videopath;
          if(videopath!="") {
            this.open = true;
            this.title = "查看结果视频";
            this.playerOptions.sources[0].src = videopath;
          }else {
            this.$modal.msg("未查到结果视频！");
          }
        }else {
          this.$modal.msg("未查到结果视频！");
        }
      });
    },
    gettaskhisList() {
      listAerationPort1(this.queryParams).then(response => {
        this.taskhisList = response.rows;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('nssc/aerationresult/cjfxjgexport', {
        ...this.queryParams
      }, `monitor_${new Date().getTime()}.xlsx`)
    },
    /** 查询机器人状态列表 */
    getList() {
      this.loading = true;
      cjfxjgReport(this.queryParams).then(response => {
        this.cjfxjgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    //取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.create_times=[];
      this.queryParams.task_his_id="";
      this.queryParams.pond_num="";
      this.queryParams.pond_name="";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中的数据项？').then(function() {
        return xjcjsjDelete(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
